<?php
namespace App\Http\Controllers\Home;

use App\Models\TimeLine;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Faker\Generator;

class TimeLineController extends Controller{

    public function index()
    {
        return response(TimeLine::all()->jsonSerialize(),Response::HTTP_OK);
    }


    //添加
    public function save(Request $request){
        
        //数据获取
        $author = $request->input('author');
        $color = $request->input('color','orange');
        $title = $request->input('title');
        $content = $request->input('content');

        $now = date('Y-m-d H:i:s');

        //数据验证


        //入库操作
        $timeline = new TimeLine();
        $timeline->author = $author;
        $timeline->color = $color;
        $timeline->title = $title;
        $timeline->content = $content;
        /*
        $timeline->updated_at = $now;
        $timeline->created_at = $now;
        */
        $data = [];
        $res = $timeline->save();  //添加成功返回true

        if($res){
            $data = [
                'code'=>200,
                'msg'=>'添加成功',
                'list'=>$timeline->jsonSerialize()
            ];
        }else{
            $data = [
                'code'=>100,
                'msg'=>'添加失败'
            ];
        }

        //return response($timeline->jsonSerialize(),Response::HTTP_CREATED);

        //return response($timeline->jsonSerialize());
        return response()->json($data);


    }




}